const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
    entry: {
        index: '/src/index.js'
    },
    resolve: {
        extensions: [".js", ".jsx"],
        alias: {
            "@": path.resolve(__dirname, '../src')
        }
  },
  target: "electron-renderer",
  node: {
    __dirname: false
  },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'babel-loader'
                  },
                  {
                      loader: 'eslint-loader'
                  }
                ]
            },
            {
                test: /.less$/,
                use: [
                  devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
                    { loader: 'css-loader' },
                    { loader: 'postcss-loader' },
                  {
                    loader: 'less-loader', options: {
                      lessOptions: {
                        javascriptEnabled: true
                        }
                      }
                    }
                ]
            },
            {
                test: /\.(png|jpg|jpeg|gif|svg)/,
                use: {
                  loader: 'url-loader',
                  options: {
                    outputPath: 'images/', // 图片输出的路径
                    limit: 10 * 1024
                  }
                }
            },
            {
                test: /\.(eot|woff2?|ttf|svg)$/,
                use: [
                  {
                    loader: 'url-loader',
                  }
                ]
              }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: 'public/index.html',
            inject: 'body',
            minify: {
                removeComments: true,
                collapseWhitespace: true
            },
            favicon: path.resolve(__dirname, '../public/favicon.ico')
        }),
        new MiniCssExtractPlugin({
            filename: '[name].css'
        })
    ]
}
